package com.lantu;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class CROSInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
        // 取得请求相关的ActionContext实例  
        ActionContext ctx = invocation.getInvocationContext();
        HttpServletRequest request = ServletActionContext.getRequest();  
        HttpServletResponse response = ServletActionContext.getResponse();
        if(request.getMethod().equals("OPTIONS")){
        	response.setHeader("Access-Control-Allow-Origin","*");
        	response.setHeader("Access-Control-Allow-Methods","POST");
        	response.setHeader("Access-Control-Allow-Headers","x-requested-with,content-type");
        }
        return invocation.invoke();  
	}

}
